/** 
 * This file is a part of qloudgen-sec. 
 * You can redistribute qloudgen-sec and/or modify it under the terms of the Lesser GNU General Public License version 3. 
 * qloudgen-sec is distributed WITHOUT ANY WARRANTY. 
 *
 * See the Lesser GNU General Public License for more details at http://www.gnu.org/licenses/. 
 **/
package org.qloudgen.sec.util;

import java.io.PrintStream;
import java.io.ByteArrayOutputStream;

/**
 * <p>Title: Exception tools.</p>
 * <p>Description: Implementation exception stack message print.</p>
 * <p>Copyright: qloudgen/sec 2010</p>
 * @author <a href="mailto:hyq.dd.sun@gmail.com">glue.3M</a>
 */
public final class ExceptionUtil {
	/**
	 * Returns current exception all stack message.
	 *
	 * @param t
	 * @return String
	 */
	public static String get(Throwable t) {
		//
		if ( t == null ) {
			return "NULL";
		}
		// Create
		StringBuilder b = new StringBuilder();
		//
		b.append( t.getMessage() );
		b.append( "\n" );
		//
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		PrintStream ps = new PrintStream( baos );
		//
		t.printStackTrace( ps );
		//
		b.append( baos.toString() );
		//
		return b.toString();
	}
}